﻿using System;
using System.Collections.Generic;
using System.Text;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Entities;
using System.Data.SqlClient;
using System.Data;

namespace NIIT.SaoBacDau.Aupi.HospitalManagement.DataAccess
{
    public class DAO_E_DugType
    {
        public static void AddDrugType(E_DugType drug)
        {
            SqlConnection conn = DAO_ConnectDatabase.Connect();
            try
            {
                conn.Open();
                SqlCommand sqlcom = new SqlCommand("insert into Equipment.DrugType (DrugTypeID,DrugTypeName) values(@DrugTypeID,@DrugTypeName)", conn);

                sqlcom.Parameters.Add("@DrugTypeID", SqlDbType.Int).Value = drug.DrugTypeID1;
                sqlcom.Parameters.Add("@DrugTypeName", SqlDbType.NVarChar).Value = drug.NameDrugType;

                sqlcom.ExecuteNonQuery();
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }
        }

        public static int DrugTypeID()
        {
            SqlDataAdapter ad = new SqlDataAdapter("Select * from Equipment.DrugType",DAO_ConnectDatabase.Connect());
            DataTable tb = new DataTable();
            ad.Fill(tb);
            return tb.Rows.Count + 1;
        }

        public static DataTable E_DrugType()
        {
            SqlConnection conn = DAO_ConnectDatabase.Connect();
            try
            {
                conn.Open();
                SqlDataAdapter sda = new SqlDataAdapter("select DrugTypeID from Equipment.DrugType ", conn);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                return dt;
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }
        }
    }
}
